Contemporary computing systems and devices implement the concept of multi-threaded programming. Multi-threaded programs can be executed on one or more processing units by dividing the programs into concurrently running tasks, such as threads. During the course of their execution, one or more threads may seek to share access to resources, such as memory addresses, files, etc. The access should not be concurrent so as to prevent output that may be erroneous. Logical mechanisms, such as mutual exclusion locks (mutex locks) ensure that a shared resource, being utilized by one thread, remains isolated from any subsequent incoming threads that seek to gain access to the same shared resource. The subsequent incoming threads, in such a case, may either sleep or may spin on the mutex lock till it is released and is made available again for acquiring.
The spinning of any thread can be specified by a busy-wait time. The default busy-wait time sets the number of spins the threads may make to acquire the mutex lock before sleeping. A thread spinning with the default spin value may consume a considerable amount of computational resources during execution.
Mutex locks can also be associated with condition variables. A thread, after acquiring a mutex lock which is associated with a condition variable, can either access the shared resource when the state of the condition variable is favorable or wait until the state of the condition variable becomes favorable. Once the state of the condition variable becomes favorable, the thread waiting on the condition variable can be called to acquire the mutex and gain access to the shared resource. Such a thread may spin on the mutex lock, if the mutex lock is not available.